package steven.sdc.appPoker.Fragment;
import java.util.ArrayList;

import steven.sdc.appPoker.Adapter.AdapterCauHinhNguoiChoi;
import steven.sdc.appPoker.Adapter.AdapterNguoiChoi;
import steven.sdc.appPoker.Items.ItemNguoiChoi;

import com.amurani.slidingmenu.R;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class FragmentTaoGame extends Fragment{
	ImageView btn_add;
	ImageView btn_cauhinh,btn_cauhinhnguoichoi,img_group;
	ArrayList<ItemNguoiChoi> items;
	Button btn_vaochoi;
	AdapterCauHinhNguoiChoi adapter;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.chonnguoichoi, container, false);
		Init(view);
		return view;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		ButtonEvent();
	}
	public void ButtonEvent()
	{
		btn_add.setOnClickListener(dt);
		btn_cauhinh.setOnClickListener(dt);
		btn_vaochoi.setOnClickListener(dt);
		btn_cauhinhnguoichoi.setOnClickListener(dt);
		
	}
	OnClickListener dt=new OnClickListener() {
		
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.btn_vaochoi:
			{
				FragmentBangDiem frag_bangdiem= new FragmentBangDiem();
				getFragmentManager().beginTransaction().add(R.id.fragment_content, frag_bangdiem,null).addToBackStack(null).commitAllowingStateLoss();
			}
				break;
			case R.id.btn_add:
			{
				FragmentNguoiChoi temp = new FragmentNguoiChoi();
				getFragmentManager().beginTransaction().add(R.id.fragment_content, temp,null).addToBackStack(null).commitAllowingStateLoss();
			}
				
				break;
			case R.id.button_cauhinh:
			{
				FragmentCauHinh frag_cauhinh = new FragmentCauHinh();
				getFragmentManager().beginTransaction().replace(
					       R.id.fragment_content, frag_cauhinh, null).commitAllowingStateLoss();
			}
				
				break;
			case R.id.btn_cauhinhnguoichoi:
			{
				final Dialog temp = new Dialog(getActivity());
				temp.setContentView(R.layout.custom);
				temp.setTitle("Chọn người chơi");
				//temp.setCancelable(true);
				
				AutoCompleteTextView auto = (AutoCompleteTextView) temp.findViewById(R.id.auto_txt_nguoi1);
				items = new ArrayList<ItemNguoiChoi>();	
				
				ListView list = (ListView) temp.findViewById(R.id.list_custom);
				Button btn_dongy = (Button) temp.findViewById(R.id.btn_custom_dongy);
				Button btn_trove = (Button) temp.findViewById(R.id.btn_custom_trove);
				btn_trove.setOnClickListener(new OnClickListener() {
					
					public void onClick(View v) {
						// TODO Auto-generated method stub
						temp.cancel();
					}
				});
				adapter=new AdapterCauHinhNguoiChoi(getActivity(), R.layout.list_item_cauhinhnguoichoi, items);
				List();
				list.setAdapter(adapter);
				
				temp.show();
				break;
//				FragmentCauHinhNguoiChoi dt=new FragmentCauHinhNguoiChoi();
//				getFragmentManager().beginTransaction().replace(
//					       R.id.fragment_content, dt, null).commitAllowingStateLoss();
			}
			default:
				break;
			}
			
		}
	};
	
	public void List()
	{
		items.add(new ItemNguoiChoi("Bình"));
		items.add(new ItemNguoiChoi( "Tiến"));
		items.add(new ItemNguoiChoi("Tiến"));
		items.add(new ItemNguoiChoi( "Hoàng"));
		items.add(new ItemNguoiChoi( "Hoàng"));
		items.add(new ItemNguoiChoi("Tiến"));
		items.add(new ItemNguoiChoi("Tien"));
		items.add(new ItemNguoiChoi("Bình"));
		items.add(new ItemNguoiChoi( "Nhân"));
		items.add(new ItemNguoiChoi("Nhân"));
		items.add(new ItemNguoiChoi( "Nhân"));
		items.add(new ItemNguoiChoi( "Tiến"));
		items.add(new ItemNguoiChoi("Nhân"));
		items.add(new ItemNguoiChoi("Hoàng"));
		
		adapter.notifyDataSetChanged();
		
	}
	
	public void Init(View view)
	{
		btn_vaochoi = (Button) view.findViewById(R.id.btn_vaochoi);
		btn_add = (ImageView) view.findViewById(R.id.btn_add);
		btn_cauhinh=(ImageView)view.findViewById(R.id.button_cauhinh);
		btn_cauhinhnguoichoi=(ImageView)view.findViewById(R.id.btn_cauhinhnguoichoi);
		img_group = (ImageView) view.findViewById(R.id.imageView_group);
		
		
	}
	
	}
